/*************************************************************************
	> File Name: 239_hz.cpp
	> Author: zhangxu 
	> Mail: walrus1983@126.com
	> Created Time: 四  7/11 09:22:32 2024
 ************************************************************************/
/*
1. 分形系统
2. 编号：
3. 坐标变换
(x, y) 顺时针90度	(y, n - x - 1)
(x, y) 逆时针90度	(m - y - 1, x)
(x, y) 轴对称		(x, m - y - 1)
4.当前城市等级 n，上一级位n - 1，边长L = pow(2, n - 1)
假设已计算出对应区域点在原图中的坐标(x, y)
1) 顺时针90度 -> 轴对称
(x, y) -> (y, L - x - 1) -> (y, x)
2) 向左平移
(x, y) -> (x, y + L)
3) 
(x, y) -> (x + L, y + L)
4) 逆时针90 -> 轴对称 -> 向下平移
(x, y) -> (L - y - 1, x) -> (L - y - 1, L - x - 1) -> (2L - y - 1, L - x - 1)
*/
#include<iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PAIR;

PAIR Solve(int n, LL id) {
	if(n == 1) {
		if(id == 1) return PAIR(0, 0);
		else if(id == 2) return PAIR(0, 1);
		else if(id == 3) return PAIR(1, 1);
		else return PAIR(1, 0);
	}
	LL L = 1LL << (n - 1);
	LL block = L * L;
	if(id <= block) { /* (x, y) -> (y, L - x - 1) -> (y, x) */
		PAIR tmp = Solve(n - 1, id);
		return PAIR(tmp.second, tmp.first);
	} else if(id <= 2 * block) { /* (x, y) -> (x, y + L) */
		PAIR tmp = Solve(n - 1, id - block);
		return PAIR(tmp.first, tmp.second + L);
	} else if(id <= 3 * block) { /* (x, y) -> (x + L, y + L) */
		PAIR tmp = Solve(n - 1, id - 2 * block);
		return PAIR(tmp.first + L, tmp.second + L);
	} else { /* (x, y) -> (L - y - 1, x) -> (L - y - 1, L - x - 1) -> (2L - y - 1, L - x - 1) */
		PAIR tmp = Solve(n - 1, id - 3 * block);
		return PAIR(2 * L - tmp.second - 1, L - tmp.first - 1);
	}
}

int main() {
	int t, n;
	LL s, d; //t:测试组数, n:n级城市
	scanf("%d", &t);
	while(t--) {
		scanf("%d%lld%lld", &n, &s, &d);
		PAIR p1 = Solve(n, s);
		PAIR p2 = Solve(n, d);
		LL x = p1.first - p2.first;
		LL y = p1.second- p2.second;
		printf("%.0lf\n", 10 * sqrt(x * x + y * y));
	}
	return 0;
}